let students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]
var countStudents = function(students, sandwiches) {
    let s0=0
    let s1=0
    for(let i=0;i<students.length;i++){
        if(students[i]==0){
            s0++
        }else{
            s1++
        }
    }
    while(sandwiches.length){
        if(sandwiches[0]==0&&s0>0){
            s0--
            sandwiches.shift()
        }else if(sandwiches[0]==1&&s1>0){
            s1--
            sandwiches.shift()
        }
        else{
            break;
        }
    }
    return s0+s1
    
}
console.log(countStudents(students,sandwiches));
